package com.ssly.weixin.xichang.util;

import com.shcm.bean.SendResult;
import com.shcm.send.OpenApi;

import java.util.List;

public class SMS {
    /*莫名短信验证发送所需信息*/
    private static final String sOpenUrl = "http://smsapi.duanxin.cm/OpenPlatform/OpenApi";

    //企业账号
    private static final String account = "1001@904007340001";
    //企业密匙
    private static final String authkey = "0694B9007C148FD96386354675C919B4";
    //通道组id
    private static final int cgid = 7255;
    //短信签名编号
    private static final int csid = 0;

    public boolean send(String phoneNumber, String message) {
        // 发送参数
        OpenApi.initializeAccount(sOpenUrl, account, authkey, cgid, csid);


//        if(true){
//            System.out.println(content);
//            return true;
//        }

        List<SendResult> sendResultList = OpenApi.sendOnce(phoneNumber, message, 0, 0, null);

        for (SendResult t : sendResultList) {
            if (t.getResult() < 1) {
//                发送失败
                return false;
            }
//          发送成功
            return true;
        }
        return true;
    }
    // 发送手机验证码
    public boolean sendVerifyCode(String phoneNumber) {
        String verifyCode = verifyCodeGenerator();
        return send(phoneNumber, verifyCode);
    }

    private String verifyCodeGenerator() {
        return String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
    }
}
